<template>
  <el-dialog title="审核优惠券" v-el-drag-dialog :visible.sync="editVisible">
    <el-container>
      <el-form ref="form" :model="form"  label-width="auto" >
        <el-form-item label="名称：" prop="name">
          <span>{{form.name}}</span>
        </el-form-item>
        <el-form-item label="类型：" prop="type">
          <span>{{form.type|watchType}}</span>
        </el-form-item>
        <el-form-item label="适用范围：" prop="scope">
          <span>{{form.scope|watchScope}}</span>
        </el-form-item>
        <el-form-item label="发行张数：" prop="stock" >
          <span>{{form.stock==0?0:form.stock}}</span>
        </el-form-item>
        <el-form-item label="开始时间：" prop="beginDate" v-if="form.beginDate">
          <span>{{form.beginDate|datetimeFormatter}}</span>
        </el-form-item>
        <el-form-item label="结束时间：" prop="beginDate" v-if="form.endDate">
          <span>{{form.endDate|datetimeFormatter}}</span>
        </el-form-item>
        <el-form-item label="使用说明：" prop="beginDate" v-if="form.introduction">
          <span>{{form.introduction}}</span>
        </el-form-item>
      </el-form>
    </el-container>
    <div slot="footer" class="dialog-footer">
      <el-button @click="editVisible = false">取 消</el-button>
      <el-button type="primary" @click="updatePromotion">审 核</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import {updateCoupon,find} from '../../../api/coupon'
  import elDragDialog from '@/directive/el-drag-dialog'
  export default {
    name: 'coupon-examine',
    directives: {elDragDialog},
    data(){
      return{
        editVisible:false,
        form:{}
      }
    },
    methods:{
      findCoupon(id){
        find(id).then(res=>{
          this.form=res.data.coupon
        })
      },
      updatePromotion(){
        this.$confirm('确认审核?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            this.form.status=1
            updateCoupon(this.form).then(res=>{
              this.editVisible=false
              this.$emit('loadCoupon')
            })
        })
      }

    },
    filters:{
      watchScope(val){
        if(val == 0){
          return '全场'
        }else if(val == 1){
          return '店内'
        }else if(val == 2){
          return '商城'
        }
      },
      watchType(val){
        if(val == 0){
          return '满减'
        }else if(val == 1){
          return '满折'
        }else if(val == 2){
          return '满赠'
        }else if(val == 3){
          return '兑换券'
        }
      },
    },

  }
</script>

<style scoped>
  .popup_content {
    padding-bottom: 0px !important;
  }
  .el-footerBox {
    height: 50px !important;
    line-height: 50px !important;
    border-top: 1px solid #eeeeee;
  }

  /deep/ .el-dialog__header {
    border: 1px solid #eeeeee !important;
    padding: 15px !important;
  }

  /deep/ .el-dialog__body {
    padding: 0px 20px !important;
  }
</style>
